<template>
    <div class="mainDiv">
        <div class="rowHead">
            <el-button type="success" icon="plus" @click="addbrand" v-qx="permission.add">新增品牌</el-button>
            <el-select v-model="page.zt" class="ml" @change="getList" v-qx="permission.status">
                <el-option v-for="s in status" :label="s.txt" :value="s.val">
                </el-option>
            </el-select>
            <el-button type="primary" icon="h-shuaxin1" class="buttonLeft" @click="getList">刷新列表</el-button>
            <el-input class="searchArea" placeholder="搜索品牌名称、品牌描述" @keyup.enter.native="getList" v-model="page.search">
                <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="getList"></i>
            </el-input>
        </div>
        <el-table :data="list" :stripe="true" height="100%">
            <el-table-column prop="id" label="ID" width="100"></el-table-column>
            <el-table-column prop="name" label="品牌名称"></el-table-column>
            <el-table-column prop="remarks" label="品牌描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="isdisabled" label="状态">
                <template slot-scope="scope">
                    <Tags :typeValue="scope.row.isdisabled" typeName="isDisable"></Tags>
                </template>
            </el-table-column>
            <el-table-column prop="fname" label="所属厂商"></el-table-column>
            <el-table-column prop="addtime" label="添加日期">
                <template slot-scope="scope">
                    {{scope.row.addtime|hourTime}}
                </template>
            </el-table-column>
            <el-table-column label="品牌操作">
                <template slot-scope="scope">
                    <el-button-group v-if="!scope.row.isdisabled">
                        <el-tooltip content="品牌编辑" placement="left" :open-delay="800" v-qx="permission.edit">
                            <el-button type="warning" icon="el-icon-edit" size="mini" @click="edit(scope.row)"></el-button>
                        </el-tooltip>
                        <el-tooltip content="停用品牌" placement="top" :open-delay="800" v-qx="permission.unstop">
                            <el-button type="danger" icon="el-icon-h-jinyong" size="mini" @click="stop(scope.row.id,1)"></el-button>
                        </el-tooltip>
                    </el-button-group>
                    <el-tooltip content="重新开启品牌" placement="left" :open-delay="800" v-else v-qx="permission.unstop">
                        <el-button type="success" icon="el-icon-h-qiyong2" size="mini" @click="stop(scope.row.id,0)"></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>
        <div class="block center bg-light">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="page.pages" :page-sizes="[15, 30, 50, 100]" :page-size="page.limits" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import C from '#/src/common/common.js'
import Brand from '#/src/shop/brand.js'
import Tags from '@/components/orderTags.vue'

export default {
    name: 'brandList',
    data() {
        return {
            list: [],
            total: 0,
            page: {
                pages: 1,
                limits: 15,
                search: '',
                zt: 0,
            },
            status: [{
                txt: '正常',
                val: 0
            }, {
                txt: '停用',
                val: 1
            }],
            permission: {
                add: 'brand_add',
                status: 'brand_status',
                edit: 'brand_edit',
                unstop: 'brand_unstop',
            }
        }
    },
    methods: {
        addbrand: async function() {
            let res = await Brand.openAddBrand()
            if (res && res.data) {
                C.success(res.data)
                this.getList()
            }
        },
        edit: async function(row) {
            let res = await Brand.openAddBrand(row)
            if (res && res.data) {
                C.success(res.data)
                this.getList()
            }
        },
        stop: function(id, st) {
            let that = this
            let str = st ? '停用机构品牌, 是否继续?' : '重新启用之后若被店家拉取走，将不能再次对该品牌进行修改'
            C.confirm(str, async() => {
                let res = await Brand.changeBrandStatus({ id: id, st: st })
                if (res) {
                    that.getList()
                    C.success(res.data)
                }
            })
        },
        sizeChange: function(val) {
            this.page.limits = val
            this.getList()
        },
        currentChange: function(val) {
            this.page.pages = val
            this.getList()
        },
        getList: async function() {
            let data = await Brand.getBrandList(this.page)
            if (data) {
                this.list = data.data
                this.total = data.count
            }
        }
    },
    mounted: function() {
        this.getList()
    },
    components: { Tags }
}
</script>
<style>
</style>